function fullScreen(){
    let elem: HTMLElement = document.documentElement;
    if (elem.requestFullscreen) {
        elem.requestFullscreen();
    } else if ((<any>elem).webkitRequestFullscreen) { // Safari
        (<any>elem).webkitRequestFullscreen();
    } else if ((<any>elem).msRequestFullscreen) { // IE
        (<any>elem).msRequestFullscreen();
    }
}

function fullScreenExit(){
    let elem: HTMLElement = document.documentElement;
    if (document.exitFullscreen) {
        document.exitFullscreen();
      } else if ((<any>document).webkitExitFullscreen) {
        (<any>document).webkitExitFullscreen();
      } else if ((<any>document).msExitFullscreen) {
        (<any>document).msExitFullscreen();
      }
}

function stringToXml(data: string):Document {
    const parser = new DOMParser();
    return parser.parseFromString(data, "application/xml");
}

function isMobile() { 
    let userAgent = window.navigator.userAgent; 
    return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent)); 
}

function blobToUrl(data: Blob):string {
    return URL.createObjectURL(data)
}

function fullScreenDiv(zIndex: number){
    const divString = `<div style="width: 100vw;height: 100vh;z-index: ${zIndex};position: absolute;left: 0px;top: 0px;background-color: #59595961;" id="fullScreenDiv"></div>`;
    let div = stringToXml(divString).getElementsByTagName("div")[0]; 
    const html = document.getElementsByTagName("html")[0]
    html.style.overflow = "hidden"
    html.append(div)
}

function fullScreenDivExit(){
    const html = document.getElementsByTagName("html")[0]
    html.style.overflow = ''
    if((<any>html.lastChild)?.id == "fullScreenDiv"){
        html.lastChild.remove();
    }
}

export {
    fullScreen,
    fullScreenExit,
    blobToUrl,
    isMobile,
    stringToXml,
    fullScreenDiv,
    fullScreenDivExit
}


